/**
 * Created with JetBrains WebStorm.
 * User: peternguyen
 * Date: 10/4/13
 * Time: 5:34 PM
 * To change this template use File | Settings | File Templates.
 */

describe('App.api_transfer', function() {
    describe('generateEtac', function() {
        it('bill payment', function() {
            var transferObj = App.BillPayment.create();
            var callback = {};
            var requester = Ember.Object.create({
                generateEtac: function(transfer, callback) {

                }
            })
            spyOn(App.GenerateBillPaymentEtac, 'create').andReturn(requester);
            spyOn(requester,'generateEtac');

            App.api_transfer.generateEtac(transferObj, callback);

            expect(requester.generateEtac).toHaveBeenCalledWith(transferObj, callback);
        });
        it('Own Account Transfer', function() {
            var transferObj = App.OwnAccountTransfer.create();
            var callback = {};
            var requester = Ember.Object.create({
                generateEtac: function(transfer, callback) {

                }
            })
            spyOn(App.GenerateOwnAccountTransferEtac, 'create').andReturn(requester);
            spyOn(requester,'generateEtac');

            App.api_transfer.generateEtac(transferObj, callback);

            expect(requester.generateEtac).toHaveBeenCalledWith(transferObj, callback);
        });
        it('3rd Party Transfer', function() {
            var transferObj = App.ThirdPartyTransfer.create();
            var callback = {};
            var requester = Ember.Object.create({
                generateEtac: function(transfer, callback) {

                }
            })
            spyOn(App.GenerateThirdPartyTransferEtac, 'create').andReturn(requester);
            spyOn(requester,'generateEtac');

            App.api_transfer.generateEtac(transferObj, callback);

            expect(requester.generateEtac).toHaveBeenCalledWith(transferObj, callback);
        });
    });

    describe('App.FromListFetcher', function(){
        var fetcher;
        beforeEach(function(){
            fetcher = App.FromListFetcher.create();
        });
        describe('fetch', function() {
            it('own account transfer', function(){
                var transferObj = App.OwnAccountTransfer.create({
                    toAccount: Ember.Object.create({
                        currencyCode: 'IDR'
                    })
                });

                spyOn(bsoi, 'filterProductList').andCallFake(function(req, callback){
                    callback(transferObj, {});
                });
                spyOn(fetcher, 'processList');

                fetcher.fetch(transferObj, {});

                expect(bsoi.filterProductList).toHaveBeenCalledWith({
                    productFilter:{"functionCode" : 'FUNC_FT_OWN', "crDrFlag" : "DR", "currencyCode" : 'IDR'},
                    requestHeader : App.getSession().getBreezeContext()
                }, jasmine.any(Function));
                expect(fetcher.processList).toHaveBeenCalled();
            });
            it('ThirdParty transfer - Other SCB', function(){

                var t_payee = App.ThirdPartyPayee.create({
                    accountCurrency: 'IDR',
                    payeeType:'1'
                });

                var transferObj = App.ThirdPartyTransfer.create({
                    init:function(){
                        this.set('payee', t_payee);
                    }
                });

                spyOn(bsoi, 'filterProductList').andCallFake(function(req, callback){
                    callback(transferObj, {});
                });
                spyOn(fetcher, 'processList');

                fetcher.fetch(transferObj, {});

                expect(bsoi.filterProductList).toHaveBeenCalledWith({
                    productFilter:{"functionCode" : 'FUNC_FT_OTHER_SCB', "crDrFlag" : "DR", "currencyCode" : 'IDR'},
                    requestHeader : App.getSession().getBreezeContext()
                }, jasmine.any(Function));
                expect(fetcher.processList).toHaveBeenCalled();
            });

            it('ThirdParty transfer - IBFT', function(){

                var t_payee = App.ThirdPartyPayee.create({
                    accountCurrency: 'IDR',
                    payeeType:'2'
                });

                var transferObj = App.ThirdPartyTransfer.create({
                    init:function(){
                        this.set('payee', t_payee);
                    }
                });

                spyOn(bsoi, 'filterProductList').andCallFake(function(req, callback){
                    callback(transferObj, {});
                });
                spyOn(fetcher, 'processList');

                fetcher.fetch(transferObj, {});

                expect(bsoi.filterProductList).toHaveBeenCalledWith({
                    productFilter:{"functionCode" : 'FUNC_FT_OTHER_BANK', "crDrFlag" : "DR", "currencyCode" : 'IDR'},
                    requestHeader : App.getSession().getBreezeContext()
                }, jasmine.any(Function));
                expect(fetcher.processList).toHaveBeenCalled();
            });

            it('others', function(){
                var transferObj = App.CreditCardPayment.create();
                spyOn(bsoi, 'filterProductList');
                fetcher.fetch(transferObj, {});
                expect(bsoi.filterProductList).toHaveBeenCalled();
            })
        });
    });

    describe('App.AcceptBillPaymentTransfer', function() {
        var acceptBillPaymentTransfer;
        var transferObject;
        beforeEach(function() {
            acceptBillPaymentTransfer = App.AcceptBillPaymentTransfer.create();
            transferObject = App.BillPayment.create();
        });
        it('error response', function() {
            spyOn(bsoi, 'validateResponse').andThrow(BreezeException.create());
            spyOn(acceptBillPaymentTransfer, 'callbackTransfer');

            acceptBillPaymentTransfer.processAcceptTransferResponse(transferObject, {});
            expect(acceptBillPaymentTransfer.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
        });
        it('success response', function(){
            spyOn(bsoi, 'validateResponse');
            spyOn(acceptBillPaymentTransfer, 'callbackTransfer');

            acceptBillPaymentTransfer.processAcceptTransferResponse(transferObject, {});
            expect(acceptBillPaymentTransfer.callbackTransfer).toHaveBeenCalledWith(jasmine.any(Ember.Object));
        });
    });

    describe('App.AcceptOwnAccountTransfer', function() {
        var acceptOwnAccountFundsTransfer;
        var transferObject;
        beforeEach(function() {
            acceptOwnAccountFundsTransfer = App.AcceptOwnAccountTransfer.create();
            transferObject = App.OwnAccountTransfer.create();
        });
        it('error response', function() {
            spyOn(bsoi, 'validateResponse').andThrow(BreezeException.create());
            spyOn(acceptOwnAccountFundsTransfer, 'callbackTransfer');

            acceptOwnAccountFundsTransfer.processAcceptTransferResponse(transferObject, {});
            expect(acceptOwnAccountFundsTransfer.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
        });
        it('success response', function(){
            spyOn(bsoi, 'validateResponse');
            spyOn(acceptOwnAccountFundsTransfer, 'callbackTransfer');

            acceptOwnAccountFundsTransfer.processAcceptTransferResponse(transferObject, {ownFundTransferResponse: {fundTransfer: {}}});
            expect(acceptOwnAccountFundsTransfer.callbackTransfer).toHaveBeenCalledWith(jasmine.any(Ember.Object));
        });
    });

    describe('App.AcceptThirdPartyTransfer', function() {
        var acceptThirdPartyTransfer;
        beforeEach(function(){
            acceptThirdPartyTransfer = App.AcceptThirdPartyTransfer.create();
        });
        describe('processAcceptTransferResponse', function() {
            it('error response', function() {
                spyOn(bsoi, 'validateResponse').andThrow(BreezeException.create());
                spyOn(acceptThirdPartyTransfer, 'callbackTransfer');

                acceptThirdPartyTransfer.processAcceptTransferResponse({});
                expect(acceptThirdPartyTransfer.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
            });
            it('success but empty response', function() {
                var response = {
                    thirdPartyFundTransferResponse: {
                    }
                };

                spyOn(bsoi, 'validateResponse');
                spyOn(acceptThirdPartyTransfer, 'callbackTransfer');

                acceptThirdPartyTransfer.processAcceptTransferResponse(response);
                expect(acceptThirdPartyTransfer.callbackTransfer).toHaveBeenCalledWith(null);
            });
            it('success response', function() {
                var response = {
                    thirdPartyFundTransferResponse: {
                        fundTransfer: {

                        }
                    }
                };

                spyOn(bsoi, 'validateResponse');
                spyOn(acceptThirdPartyTransfer, 'callbackTransfer');

                acceptThirdPartyTransfer.processAcceptTransferResponse(response);
                expect(acceptThirdPartyTransfer.callbackTransfer).toHaveBeenCalledWith(Ember.Object.create(response.thirdPartyFundTransferResponse.fundTransfer));
            });
        })
    });

    describe('App.AcceptOneTimeBillPaymentTransfer', function() {
        var acceptOneTimeBillPaymentTransfer;
        var transferObject;
        beforeEach(function() {
            acceptOneTimeBillPaymentTransfer = App.AcceptOneTimeBillPaymentTransfer.create();
            transferObject = App.BillPayment.create();
        });
        it('error response', function() {
            spyOn(bsoi, 'validateResponse').andThrow(BreezeException.create());
            spyOn(acceptOneTimeBillPaymentTransfer, 'callbackTransfer');

            acceptOneTimeBillPaymentTransfer.processAcceptTransferResponse(transferObject, {});
            expect(acceptOneTimeBillPaymentTransfer.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
        });
        it('success response', function(){
            spyOn(bsoi, 'validateResponse');
            spyOn(acceptOneTimeBillPaymentTransfer, 'callbackTransfer');

            acceptOneTimeBillPaymentTransfer.processAcceptTransferResponse(transferObject, {});
            expect(acceptOneTimeBillPaymentTransfer.callbackTransfer).toHaveBeenCalledWith(jasmine.any(Ember.Object));
        });
    });

    describe('App.GenerateBillPaymentEtac', function() {
        var etacGenerator;
        beforeEach(function(){
            etacGenerator = App.GenerateBillPaymentEtac.create();
            t_response= {
                "billPaymentResponse":{
                    "responseHeader":{
                        "status":1,
                        "nonce":"06631fea464bf4ab199e0385e6982814",
                        "currentTimestamp":"2013-04-24T20:02:45.832+0800"
                    },
                    "isOTPRequired":true,
                    "payment":{
                        "transactionRefNo":"156100",
                        "currencyCode":"IDR",
                        "etacReqId":"BPYID20130424000034ID01I0211000521",
                        "etacMobileNo":"919551614141",
                        "amount":2000.00,
                        "recurring":{},
                        "fromAccount":{
                            "accountNumber":"25728357148",
                            "currencyCode":"IDR",
                            "productCategory":"CASA"},
                        "payee":{
                            "payeeId":44060,
                            "accountPin":0,
                            "biller":{
                                "billerId":103,
                                "seqNo":0,
                                "billerAccountPin":0,
                                "billerValidations":[
                                    {"field":"Mobile Number",
                                        "value":"083123232323"}]}
                        }
                    }
                }
            };
        });
        it('generateEtac', function() {
            var transferObj = App.BillPayment.create();
            var callback = {};
            var responseObj = {};
            var sessionObj = Ember.Object.create({
                getBreezeContext: function() {
                }
            });
            var contextObj = Ember.Object.create();
            var requestObj = Ember.Object.create();

            spyOn(bsoi, 'billPayment').andCallFake(function(request, callback) {
                callback(responseObj);
            });
            spyOn(App,'getSession').andReturn(sessionObj);
            spyOn(sessionObj, 'getBreezeContext').andReturn(contextObj);
            spyOn(transferObj, 'transferDataForGenerateEtac').andReturn(requestObj);

            spyOn(etacGenerator, 'processGenerateEtacResponse');

            etacGenerator.generateEtac(transferObj, callback);

            expect(etacGenerator.processGenerateEtacResponse).toHaveBeenCalledWith(transferObj, responseObj);
        });

        it('App.GenerateBillPaymentEtac.processGenerateEtac.error response', function() {
            transferObject = App.BillPayment.create();
            spyOn(bsoi, 'validateResponse').andThrow(BreezeException.create());
            spyOn(etacGenerator, 'callbackTransfer');

            etacGenerator.processGenerateEtacResponse(transferObject, {});
            expect(etacGenerator.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
        });
        it('App.GenerateBillPaymentEtac.processGenerateEtac.success response', function(){
            transferObject = App.BillPayment.create();
            spyOn(bsoi, 'validateResponse');
            spyOn(etacGenerator, 'callbackTransfer');

            etacGenerator.processGenerateEtacResponse(transferObject, t_response);
            var Object = App.EtactResult.create(t_response.billPaymentResponse.payment);
            expect(etacGenerator.callbackTransfer).toHaveBeenCalledWith(Object);
        });
    });

    describe('App.GenerateOwnAccountTransferEtac', function() {
        var etacGenerator;
        var t_ownAccountResponse;
        beforeEach(function(){
            etacGenerator = App.GenerateOwnAccountTransferEtac.create();
            t_ownAccountResponse = {"ownFundTransferResponse":
                                        {"responseHeader":{
                                            "status":1,
                                            "nonce":"2866a390e0a5c63c2ad1d20fba930fd8",
                                            "currentTimestamp":"2013-04-18T20:02:42.229+0800"
                                        },
                                            "isOTPRequired":true,
                                            "fundTransfer":{
                                                "currencyCode":"IDR",
                                                "remark":"dsdsdsd",
                                                "etacReqId":"A2AID20130418000091ID01I0211002749",
                                                "etacMobileNo":"919551614141",
                                                "amount":390.00,
                                                "debitAmount":1,
                                                "exchangeRate":1.000000000,
                                                "recurring":{},
                                                "transferFXRate":{},
                                                "fromAccount":{
                                                    "accountNumber":"25728357148",
                                                    "currencyCode":"IDR",
                                                    "productCategory":"CASA"
                                                },
                                                "toAccount":{
                                                    "accountNumber":"25728357150",
                                                    "currencyCode":"IDR",
                                                    "productCategory":"CASA"
                                                }
                                            }
                                        }
                                   };
        });
        it('generateEtac', function() {
            var transferObj = App.OwnAccountTransfer.create();
            var callback = {};
            var responseObj = {};
            var sessionObj = Ember.Object.create({
                getBreezeContext: function() {
                }
            });
            var contextObj = Ember.Object.create();
            var requestObj = Ember.Object.create();

            spyOn(bsoi, 'ownAccountTransfer').andCallFake(function(request, callback) {
                callback(responseObj);
            });
            spyOn(App,'getSession').andReturn(sessionObj);
            spyOn(sessionObj, 'getBreezeContext').andReturn(contextObj);
            spyOn(transferObj, 'transferDataForGenerateEtac').andReturn(requestObj);

            spyOn(etacGenerator, 'processGenerateEtacResponse');

            etacGenerator.generateEtac(transferObj, callback);

            expect(etacGenerator.processGenerateEtacResponse).toHaveBeenCalledWith(transferObj, responseObj);
        });
        it('App.GenerateOwnAccountTransferEtac.processGenerateEtacResponse.error response', function() {
            var transferObj = App.OwnAccountTransfer.create();
            spyOn(bsoi, 'validateResponse').andThrow(BreezeException.create());
            spyOn(etacGenerator, 'callbackTransfer');

            etacGenerator.processGenerateEtacResponse(transferObj, {});
            expect(etacGenerator.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
        });
        it('App.GenerateOwnAccountTransferEtac.processGenerateEtacResponse.success response', function(){
            var transferObj = App.OwnAccountTransfer.create();
            spyOn(bsoi, 'validateResponse');
            spyOn(etacGenerator, 'callbackTransfer');

            etacGenerator.processGenerateEtacResponse(transferObj, t_ownAccountResponse);
            var Object = App.EtactResult.create(t_ownAccountResponse.ownFundTransferResponse.fundTransfer);
            expect(etacGenerator.callbackTransfer).toHaveBeenCalledWith(Object);
        });


    });

    describe('App.GenerateThirdPartyTransferEtac', function() {
        var etacGenerator;
        beforeEach(function(){
            etacGenerator = App.GenerateThirdPartyTransferEtac.create();
        });
        it('generateEtac', function() {

            var t_payee = App.ThirdPartyPayee.create({
                type:'1'
            });

            var transferObj = App.ThirdPartyTransfer.create({
                init:function(){
                    this.set('payee', t_payee);
                }
            });
            var callback = {};
            var responseObj = {};
            var sessionObj = Ember.Object.create({
                getBreezeContext: function() {
                }
            });
            var contextObj = Ember.Object.create();
            var requestObj = Ember.Object.create();

            spyOn(bsoi, 'thirdPartyTransfer').andCallFake(function(request, callback) {
                callback(responseObj);
            });
            spyOn(App,'getSession').andReturn(sessionObj);
            spyOn(sessionObj, 'getBreezeContext').andReturn(contextObj);
            spyOn(transferObj, 'transferDataForGenerateEtac').andReturn(requestObj);

            spyOn(etacGenerator, 'processGenerateEtacResponse');

            etacGenerator.generateEtac(transferObj, callback);

            expect(bsoi.thirdPartyTransfer).toHaveBeenCalled();
            expect(etacGenerator.processGenerateEtacResponse).toHaveBeenCalledWith(transferObj, responseObj);
        });
        it('error response', function() {
            var transferObj = App.ThirdPartyTransfer.create();
            spyOn(bsoi, 'validateResponse').andThrow(BreezeException.create());
            spyOn(etacGenerator, 'callbackTransfer');

            etacGenerator.processGenerateEtacResponse(transferObj, {});
            expect(etacGenerator.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
        });
        it('success response', function(){
            var transferObj = App.ThirdPartyTransfer.create();
            var responseData = {"thirdPartyFundTransferResponse":
            {"responseHeader":{
                "status":1,
                "nonce":"2866a390e0a5c63c2ad1d20fba930fd8",
                "currentTimestamp":"2013-04-18T20:02:42.229+0800"
            },
                "isOTPRequired":true,
                "fundTransfer":{
                    "currencyCode":"IDR",
                    "remark":"dsdsdsd",
                    "etacReqId":"A2AID20130418000091ID01I0211002749",
                    "etacMobileNo":"919551614141",
                    "amount":390.00,
                    "debitAmount":1,
                    "exchangeRate":1.000000000,
                    "recurring":{},
                    "transferFXRate":{},
                    "fromAccount":{
                        "accountNumber":"25728357148",
                        "currencyCode":"IDR",
                        "productCategory":"CASA"
                    },
                    "toAccount":{
                        "accountNumber":"25728357150",
                        "currencyCode":"IDR",
                        "productCategory":"CASA"
                    }
                }
            }
            };
            spyOn(bsoi, 'validateResponse');
            spyOn(etacGenerator, 'callbackTransfer');

            etacGenerator.processGenerateEtacResponse(transferObj, responseData);
            var Object = App.EtactResult.create(responseData.thirdPartyFundTransferResponse.fundTransfer);
            expect(etacGenerator.callbackTransfer).toHaveBeenCalledWith(Object);
        });


    });

    describe('App.BillPayeeListFetcher', function() {
        var fetcher;
        var transferObject;
        beforeEach(function() {
            fetcher = App.BillPayeeListFetcher.create();
            transferObject = App.BillPayment.create();
        });
        describe('fetch', function(){
            it('use the cached response if response is already cache',function(){
                var cacheObj = {};
                var transferObj = App.BillPayment.create();
                App.getSession().setAttribute('billPayment.registeredPayees', cacheObj);
                spyOn(fetcher, 'processList');
                spyOn(bsoi,'getBillPayeeList');
                fetcher.fetch(transferObj, {});
                expect(fetcher.processList).toHaveBeenCalledWith(transferObj, cacheObj);
                expect(bsoi.getBillPayeeList).not.toHaveBeenCalled();
            });
            it('call webservice if response is not in cache',function(){
                var responseObj = {};
                var transferObj = App.BillPayment.create();
                App.getSession().setAttribute('billPayment.registeredPayees', null);
                spyOn(fetcher, 'processList');
                spyOn(bsoi,'getBillPayeeList').andCallFake(function(request, callback){
                    callback(responseObj);
                });
                fetcher.fetch(transferObj, {});
                expect(bsoi.getBillPayeeList).toHaveBeenCalledWith({
                    payee: {
                        payeeType : '',
                        payeeStatus : ''
                    },
                    preferredMerchants: true,
                    requestHeader: App.getSession().getBreezeContext()
                }, jasmine.any(Function));
                expect(fetcher.processList).toHaveBeenCalledWith(transferObj, responseObj);
            });
        });
        describe('processList', function(){
            it('general exception handling', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');

                fetcher.processList(transferObject, {});

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));

            });

            it('error response handling', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(false);
                spyOn(fetcher, 'callbackTransfer');

                fetcher.processList(transferObject, {billPaymentPayeeListResponse:{responseHeader:{errorCode:'', errorMessage:''}}});

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));

            });

            it('response with no payee', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');
                spyOn(App.i18n.getTranslations(), 'get');

                fetcher.processList(transferObject, {
                    billPaymentPayeeListResponse: {
                        payeeList:[
                        ]
                    }
                });

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
                expect(App.i18n.getTranslations().get).toHaveBeenCalledWith('error.noPayeeListError');

            });

            it('response with payee after filtering', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');
                var payee = {payeeId: '1'};
                spyOn(App.BillPaymentPayee,'create').andReturn(payee);

                fetcher.processList(transferObject, {
                    billPaymentPayeeListResponse: {
                        payeeList:[
                            {
                                biller: {
                                    billerTypeCode: 'BILL_PAYMENT'
                                }
                            },
                            {
                                biller: {
                                    billerTypeCode: 'BILL_PAYMENT'
                                }
                            },
                            {
                                biller: {
                                    billerTypeCode: 'TOPUP'
                                }
                            }
                        ]
                    }
                });

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith([payee,payee]);
            });

            it('response with no payee after filtering', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');
                spyOn(App.i18n.getTranslations(), 'get');
                var payee = {payeeId: '1'};
                spyOn(App.BillPaymentPayee,'create').andReturn(payee);

                fetcher.processList(transferObject, {
                    billPaymentPayeeListResponse: {
                        payeeList:[
                            {
                                biller: {
                                    billerTypeCode: 'TOPUP'
                                }
                            }
                        ]
                    }
                });

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
                expect(App.i18n.getTranslations().get).toHaveBeenCalledWith('error.noPayeeListError');
            });

        });
    });

    describe('App.OneTimeBillPayeeListFetcher', function() {
        var fetcher;
        var transferObject;
        beforeEach(function() {
            fetcher = App.OneTimeBillPayeeListFetcher.create();
            transferObject = App.OneTimeBillPayment.create();
        });
        describe('fetch', function(){
            it('use the cached response if response is already cache',function(){
                var cacheObj = {};
                var transferObj = App.BillPayment.create();
                App.getSession().setAttribute('billPayment.billers', cacheObj);
                spyOn(fetcher, 'processList');
                spyOn(bsoi,'getBillPayeeList');
                fetcher.fetch(transferObj, {});
                expect(fetcher.processList).toHaveBeenCalledWith(transferObj, cacheObj);
                expect(bsoi.getBillPayeeList).not.toHaveBeenCalled();
            });
            it('call webservice if response is not in cache',function(){
                var responseObj = {};
                var transferObj = App.BillPayment.create();
                App.getSession().setAttribute('billPayment.billers', null);
                spyOn(fetcher, 'processList');
                spyOn(bsoi,'getBillPayeeList').andCallFake(function(request, callback){
                    callback(responseObj);
                });
                fetcher.fetch(transferObj, {});
                expect(bsoi.getBillPayeeList).toHaveBeenCalledWith({
                    payee: {
                        payeeType : '',
                        payeeStatus : ''
                    },
                    preferredMerchants: false,
                    requestHeader: App.getSession().getBreezeContext()
                }, jasmine.any(Function));
                expect(fetcher.processList).toHaveBeenCalledWith(transferObj, responseObj);
            });
        });
        describe('processList', function(){
            it('general exception handling', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');

                fetcher.processList(transferObject, {});

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));

            });

            it('error response handling', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(false);
                spyOn(fetcher, 'callbackTransfer');

                fetcher.processList(transferObject, {billPaymentPayeeListResponse:{responseHeader:{errorCode:'', errorMessage:''}}});

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));

            });

            it('response with no payee', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');
                spyOn(App.i18n.getTranslations(), 'get');

                fetcher.processList(transferObject, {
                    billPaymentPayeeListResponse: {
                        payeeList:[
                        ]
                    }
                });

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
                expect(App.i18n.getTranslations().get).toHaveBeenCalledWith('error.noPayeeListError');

            });

            it('response with data', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');
                var payee = {payeeId: '1'};
                spyOn(App.BillPaymentPayee,'create').andReturn(payee);

                fetcher.processList(transferObject, {
                    billPaymentPayeeListResponse: {
                        payeeList:[
                            {
                                biller: {
                                    billerTypeCode: 'BILL_PAYMENT'
                                }
                            },
                            {
                                biller: {
                                    billerTypeCode: 'ABC'
                                }
                            }
                        ]
                    }
                });

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith([payee]);
            });

        });
    });
    describe('App.TopUpBillPayeeListFetcher', function() {
        var fetcher;
        var transferObject;
        beforeEach(function() {
            fetcher = App.TopUpBillPayeeListFetcher.create();
            transferObject = App.BillPayment.create();
        });
        describe('fetch', function(){
            it('use the cached response if response is already cache',function(){
                var cacheObj = {};
                var transferObj = App.BillPayment.create();
                App.getSession().setAttribute('billPayment.registeredPayees', cacheObj);
                spyOn(fetcher, 'processList');
                spyOn(bsoi,'getBillPayeeList');
                fetcher.fetch(transferObj, {});
                expect(fetcher.processList).toHaveBeenCalledWith(transferObj, cacheObj);
                expect(bsoi.getBillPayeeList).not.toHaveBeenCalled();
            });
            it('call webservice if response is not in cache',function(){
                var responseObj = {};
                var transferObj = App.BillPayment.create();
                App.getSession().setAttribute('billPayment.registeredPayees', null);
                spyOn(fetcher, 'processList');
                spyOn(bsoi,'getBillPayeeList').andCallFake(function(request, callback){
                    callback(responseObj);
                });
                fetcher.fetch(transferObj, {});
                expect(bsoi.getBillPayeeList).toHaveBeenCalledWith({
                    payee: {
                        payeeType : '',
                        payeeStatus : ''
                    },
                    preferredMerchants: true,
                    requestHeader: App.getSession().getBreezeContext()
                }, jasmine.any(Function));
                expect(fetcher.processList).toHaveBeenCalledWith(transferObj, responseObj);
            });
        });
        describe('processList', function(){
            it('general exception handling', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');

                fetcher.processList(transferObject, {});

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));

            });

            it('error response handling', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(false);
                spyOn(fetcher, 'callbackTransfer');

                fetcher.processList(transferObject, {billPaymentPayeeListResponse:{responseHeader:{errorCode:'', errorMessage:''}}});

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));

            });

            it('response with no payee', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');
                spyOn(App.i18n.getTranslations(), 'get');

                fetcher.processList(transferObject, {
                    billPaymentPayeeListResponse: {
                        payeeList:[
                        ]
                    }
                });

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
                expect(App.i18n.getTranslations().get).toHaveBeenCalledWith('error.noPayeeListError');

            });

            it('response with payee after filtering', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');
                var payee = {payeeId: '1'};
                spyOn(App.BillPaymentPayee,'create').andReturn(payee);

                fetcher.processList(transferObject, {
                    billPaymentPayeeListResponse: {
                        payeeList:[
                            {
                                biller: {
                                    billerTypeCode: 'BILL_PAYMENT'
                                }
                            },
                            {
                                biller: {
                                    billerTypeCode: 'BILL_PAYMENT'
                                }
                            },
                            {
                                biller: {
                                    billerTypeCode: 'TOPUP'
                                }
                            }
                        ]
                    }
                });

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith([payee]);
            });

            it('response with no payee after filtering', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');
                spyOn(App.i18n.getTranslations(), 'get');
                var payee = {payeeId: '1'};
                spyOn(App.BillPaymentPayee,'create').andReturn(payee);

                fetcher.processList(transferObject, {
                    billPaymentPayeeListResponse: {
                        payeeList:[
                            {
                                biller: {
                                    billerTypeCode: 'BILL_PAYMENT'
                                }
                            },
                            {
                                biller: {
                                    billerTypeCode: 'BILL_PAYMENT'
                                }
                            }
                        ]
                    }
                });

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
                expect(App.i18n.getTranslations().get).toHaveBeenCalledWith('error.noPayeeListError');
            });

        });
    });

    describe('App.OneTimeTopUpBillPayeeListFetcher', function() {
        var fetcher;
        var transferObject;
        beforeEach(function() {
            fetcher = App.OneTimeTopUpBillPayeeListFetcher.create();
            transferObject = App.OneTimeTopUpPayment.create();
        });
        describe('fetch', function(){
            it('use the cached response if response is already cache',function(){
                var cacheObj = {};
                App.getSession().setAttribute('billPayment.billers', cacheObj);
                spyOn(fetcher, 'processList');
                spyOn(bsoi,'getBillPayeeList');
                fetcher.fetch(transferObject, {});
                expect(fetcher.processList).toHaveBeenCalledWith(transferObject, cacheObj);
                expect(bsoi.getBillPayeeList).not.toHaveBeenCalled();
            });
            it('call webservice if response is not in cache',function(){
                var responseObj = {};
                App.getSession().setAttribute('billPayment.billers', null);
                spyOn(fetcher, 'processList');
                spyOn(bsoi,'getBillPayeeList').andCallFake(function(request, callback){
                    callback(responseObj);
                });
                fetcher.fetch(transferObject, {});
                expect(bsoi.getBillPayeeList).toHaveBeenCalledWith({
                    payee: {
                        payeeType : '',
                        payeeStatus : ''
                    },
                    preferredMerchants: false,
                    requestHeader: App.getSession().getBreezeContext()
                }, jasmine.any(Function));
                expect(fetcher.processList).toHaveBeenCalledWith(transferObject, responseObj);
            });
        });
        describe('processList', function(){
            it('general exception handling', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');

                fetcher.processList(transferObject, {});

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));

            });

            it('error response handling', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(false);
                spyOn(fetcher, 'callbackTransfer');

                fetcher.processList(transferObject, {billPaymentPayeeListResponse:{responseHeader:{errorCode:'', errorMessage:''}}});

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));

            });

            it('response with no payee', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');
                spyOn(App.i18n.getTranslations(), 'get');

                fetcher.processList(transferObject, {
                    billPaymentPayeeListResponse: {
                        payeeList:[
                        ]
                    }
                });

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith(null, jasmine.any(BreezeException));
                expect(App.i18n.getTranslations().get).toHaveBeenCalledWith('error.noPayeeListError');

            });

            it('response with data', function(){
                spyOn(bsoi, 'isGeneralException').andReturn(false);
                spyOn(bsoi, 'isSuccessResponse').andReturn(true);
                spyOn(fetcher, 'callbackTransfer');
                var payee = {payeeId: '1'};
                spyOn(App.BillPaymentPayee,'create').andReturn(payee);

                fetcher.processList(transferObject, {
                    billPaymentPayeeListResponse: {
                        payeeList:[
                            {
                                biller: {
                                    billerTypeCode: 'BILL_PAYMENT'
                                }
                            },
                            {
                                biller: {
                                    billerTypeCode: 'TOPUP'
                                }
                            }
                        ]
                    }
                });

                expect(fetcher.callbackTransfer).toHaveBeenCalledWith([payee]);
            });

        });
    });

    describe('App.ConfirmBillPaymentTransfer', function() {
        var requester;
        beforeEach(function(){
            requester = App.ConfirmBillPaymentTransfer.create();
        });
        it('confirm', function() {
            var transferData = {
            }
            var transferObj = Ember.Object.create({
                otpToken: '123456',
                transferDataVO: function() {
                    return transferData;
                }
            });
            var callback = function() {

            };
            spyOn(bsoi, 'billPayment').andCallFake(function(request, callback){
                callback({});
            });

            spyOn(transferObj, 'get').andCallThrough();

            spyOn(requester, 'processConfirmTransferResponse');

            requester.confirm(transferObj, callback);

            expect(bsoi.billPayment).toHaveBeenCalled();
            expect(transferObj.get).toHaveBeenCalledWith('otpToken');
            expect(App.getSession().getBreezeContext().serviceContext.otpToken).toBe(null);
            expect(requester.processConfirmTransferResponse).toHaveBeenCalled();
        });
    });

    describe('App.ConfirmOwnAccountTransfer', function() {
        var requester;
        beforeEach(function(){
            requester = App.ConfirmOwnAccountTransfer.create();
        });
        it('confirm', function() {
            var transferData = {
            }
            var transferObj = Ember.Object.create({
                otpToken: '123456',
                fundTransferDataVO: function() {
                    return transferData;
                }
            });
            var callback = function() {

            };
            spyOn(bsoi, 'ownAccountTransfer').andCallFake(function(request, callback){
                callback({});
            });

            spyOn(transferObj, 'get').andCallThrough();

            spyOn(requester, 'processConfirmTransferResponse');
            spyOn(App.getSession(), 'getCurrentTransfer').andReturn(transferObj);

            requester.confirm(transferObj, callback);

            expect(bsoi.ownAccountTransfer).toHaveBeenCalled();
            expect(transferObj.get).toHaveBeenCalledWith('otpToken');
            expect(App.getSession().getBreezeContext().serviceContext.otpToken).toBe(null);
            expect(requester.processConfirmTransferResponse).toHaveBeenCalled();
        });
    });

    describe('App.ConfirmThirdPartyTransfer', function() {
        var requester,  transferObj;
        beforeEach(function(){
            requester = App.ConfirmThirdPartyTransfer.create();
            var transferData = {
            }
            var t_payee = App.ThirdPartyPayee.create({
                type:'1'
            });

            transferObj = App.ThirdPartyTransfer.create({
                init:function(){
                    this.set('payee', t_payee);
                    this.set('otpToken', '123456');
                },
                fundTransferDataVO: function() {
                    return transferData;
                }
            });
        });
        it('confirm', function() {
            var callback = function() {

            };
            spyOn(bsoi, 'thirdPartyTransfer').andCallFake(function(request, callback){
                callback({});
            });

            spyOn(transferObj, 'get').andCallThrough();

            spyOn(requester, 'processConfirmTransferResponse');
            spyOn(App.getSession(), 'getCurrentTransfer').andReturn(transferObj);

            requester.confirm(transferObj, callback);

            expect(bsoi.thirdPartyTransfer).toHaveBeenCalled();
            expect(transferObj.get).toHaveBeenCalledWith('otpToken');
            expect(App.getSession().getBreezeContext().serviceContext.otpToken).toBe(null);
            expect(requester.processConfirmTransferResponse).toHaveBeenCalled();
        });
    });
});